<template>
  <div>
    <el-dialog title="租户配置"
               :visible="showConfig"
               width="1200px"
               append-to-body @open="onOpen" @close="onClose" >
      <el-row :gutter="undefined">
        <el-form ref="tenantConfigForm" :model="tenantConfigData" :rules="rules" size="medium"
                 label-width="150px">
          <el-col :span="24">
            <el-divider content-position="left">微信小程序配置</el-divider>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app_id" prop="appId">
              <el-input v-model="tenantConfigData.appId" placeholder="请输入app_id" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="app_secret" prop="appSecret">
              <el-input v-model="tenantConfigData.appSecret" placeholder="请输入app_secret" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付证书路径" prop="certificate">
              <el-input v-model="tenantConfigData.certificate" placeholder="请输入支付证书路径" show-word-limit
                        clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">短信配置</el-divider>
          </el-col>
          <el-col :span="12">
            <el-form-item label="短信账号" prop="smsId">
              <el-input v-model="tenantConfigData.smsId" placeholder="请输入短信账号" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="短信密码" prop="smsPsw">
              <el-input v-model="tenantConfigData.smsPsw" placeholder="请输入短信密码" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">认证配置</el-divider>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否高级认证" prop="advancedMode">
              <el-radio-group v-model="tenantConfigData.advancedMode" size="medium">
                <el-radio v-for="(item, index) in advancedModeOptions" :key="index" :label="item.value"
                          :disabled="item.disabled">{{item.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="高级认证code" prop="alipayAppCode">
              <el-input v-model="tenantConfigData.alipayAppCode" placeholder="请输入高级认证code" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">百度地图配置</el-divider>
          </el-col>
          <el-col :span="24">
            <el-form-item label="百度地图AK" prop="baiduAk">
              <el-input v-model="tenantConfigData.baiduAk" placeholder="请输入百度地图AK" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">ORC识别配置</el-divider>
          </el-col>
          <el-col :span="12">
            <el-form-item label="id" prop="clientId">
              <el-input v-model="tenantConfigData.clientId" placeholder="请输入id" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="secret" prop="clientSecret">
              <el-input v-model="tenantConfigData.clientSecret" placeholder="请输入" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">支付配置</el-divider>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否测试金额" prop="payTest">
              <el-radio-group v-model="tenantConfigData.payTest" size="medium">
                <el-radio v-for="(item, index) in payTestOptions" :key="index" :label="item.value"
                          :disabled="item.disabled">{{item.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="下单延迟时间" prop="delayTime">
              <el-input v-model="tenantConfigData.delayTime" placeholder="请输入" clearable  :style="{width: '100%'}"><template slot="append">小时</template></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="免费时长" prop="freeHour">
              <el-input v-model="tenantConfigData.freeHour" placeholder="请输入" clearable :style="{width: '100%'}"><template slot="append">小时</template></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商户支付key" prop="appKey">
              <el-input v-model="tenantConfigData.appKey" placeholder="请输入" clearable :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="小程序商户号" prop="mchId">
              <el-input v-model="tenantConfigData.mchId" placeholder="请输入" clearable  :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="支付回调地址" prop="notifyUrl">
              <el-input v-model="tenantConfigData.notifyUrl" placeholder="请输入" clearable  :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="退款限制时间" prop="timeLimit">
              <el-input v-model="tenantConfigData.timeLimit" placeholder="请输入" clearable  :style="{width: '100%'}"><template slot="append">小时</template></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="退款扣除手续费" prop="serviceCharge">
              <el-input v-model="tenantConfigData.serviceCharge" placeholder="请输入" clearable  :style="{width: '100%'}"><template slot="append">元</template></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">预警配置</el-divider>
          </el-col>
          <el-col :span="12">
            <el-form-item label="保险失效预警时间" prop="insuranceDay">
              <el-input v-model="tenantConfigData.insuranceDay" placeholder="请输入" clearable :style="{width: '100%'}"><template slot="append">天</template></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="年检失效预警时间" prop="inspectionDay">
              <el-input v-model="tenantConfigData.inspectionDay" placeholder="请输入" clearable :style="{width: '100%'}"><template slot="append">天</template></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="商业险失效预警时间" prop="maintenanceDay">
              <el-input v-model="tenantConfigData.maintenanceDay" placeholder="请输入" clearable :style="{width: '100%'}">
                <template slot="append">天</template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">车辆监控配置</el-divider>
          </el-col>

          <el-col :span="12">
            <el-form-item label="车辆监控登录账号" prop="subAccountUser">
              <el-input v-model="tenantConfigData.subAccountUser" placeholder="请输入" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="车辆监控登录密码" prop="cljkPassword">
              <el-input v-model="tenantConfigData.subAccountPwd" placeholder="请输入" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">保单识别配置</el-divider>
          </el-col>

          <el-col :span="12">
            <el-form-item label="悦宝保单识别key" prop="yueBaoOcrKey">
              <el-input v-model="tenantConfigData.yueBaoOcrKey" placeholder="请输入" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="悦宝保单识别密钥" prop="yueBaoOcrSecret">
              <el-input v-model="tenantConfigData.yueBaoOcrSecret" placeholder="请输入" clearable
                        :style="{width: '100%'}"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">下单配置</el-divider>
          </el-col>

          <el-col :span="12">
            <el-form-item label="实名认证" prop="advancedMode">
              <el-radio-group v-model="tenantConfigData.certificationOrder" size="medium">
                <el-radio v-for="(item, index) in enableOptions" :key="index" :label="item.value"
                          :disabled="item.disabled">{{item.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="重复下单" prop="advancedMode">
              <el-radio-group v-model="tenantConfigData.onlyRunOrder" size="medium">
                <el-radio v-for="(item, index) in enableOptions" :key="index" :label="item.value"
                          :disabled="item.disabled">{{item.label}}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-divider content-position="left">活动模板</el-divider>
          </el-col>
          <el-col :span="24">
          <el-form-item label="" prop="template">
            <el-checkbox-group v-model="template">
              <el-checkbox v-for="item in templateList" :key="item.templateId" :label="item.templateId" :value="item.templateId">
                {{item.templateName+"-"+item.templateCode}}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div slot="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="handelConfirm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { getTenantConfig,editConfig,templateList } from "@/api/system/tenant";
export default {
  inheritAttrs: false,
  components: {},
  props: {
    showConfig: {
      type: Boolean
    },
    tenantId: {
      type: Number
    }
  },
  data() {
    return {
      tenantConfigData: {
        appId: null,
        appSecret: null,
        certificate: null,
        smsId: null,
        smsPsw: null,
        advancedMode: 2,
        alipayAppCode: null,
        baiduAk: null,
        clientId: null,
        clientSecret: null,
        payTest: 1,
        onlyRunOrder:2,
        certificationOrder:2,
		illegalAmount:0,
        template:[]

      },
      rules: {
        appId: [],
        appSecret: [],
        certificate: [],
        smsId: [],
        smsPsw: [],
        advancedMode: [],
        alipayAppCode: [],
        baiduAk: [],
        clientId: [],
        clientSecret: [],
		illegalAmount:[]
      },
      templateList:[],
      template:[],
      advancedModeOptions: [{
        "label": "是",
        "value": 1
      }, {
        "label": "否",
        "value": 2
      }],
      enableOptions: [{
        "label": "启用",
        "value": 1
      }, {
        "label": "禁用",
        "value": 2
      }],
      payTestOptions: [{
        "label": "测试金额0.01",
        "value": 1
      }, {
        "label": "实际支付",
        "value": 2
      }],
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getTemplateList();
  },
  mounted() {},
  methods: {
    getTemplateList(){
      templateList().then(response => {
        this.templateList = response;
      });
    },
    onOpen() {
      getTenantConfig(this.tenantId).then(response => {
        this.tenantConfigData = response.data;
        this.template=this.tenantConfigData.template;
      });
    },
    onClose() {
      this.$refs['tenantConfigForm'].resetFields()
      this.close()
    },
    close() {
      this.$emit('close', false)
    },
    handelConfirm() {
      this.$refs['tenantConfigForm'].validate(valid => {
        this.tenantConfigData.template=this.template;
        editConfig(this.tenantConfigData).then(response => {
          this.$modal.msgSuccess("修改成功");
          this.close()
        });
      })
    },
  }
}

</script>
<style>
.el-divider {
  background-color: #b6b3ae;
}

.el-divider__text{
  color: #b6b3ae;
  font-size: 18px;
}
</style>
